package cn.ruituo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StrUtil {
    private StrUtil() {
    }

    private static final SimpleDateFormat DF = new SimpleDateFormat("yyyy-MM-dd");

    //判断s是否是空，包括null和 ""
    public static boolean isBlank(Object s) {
        if (s == null)
            return true;
        else if (s instanceof String) {
            return s.equals("");
        }
        return false;
    }

    public static Date toDate(String str) {
        try {
            return DF.parse(str);
        } catch (ParseException e) {
           // e.printStackTrace();
        }
        return null;
    }

    public static String toStr(Date str) {
        try {
            return DF.format(str);
        } catch (Exception e) {
            //e.printStackTrace();
        }
        return "";
    }
    //去除null
    public static String toStr(String str) {
        if (str == null)
            return "";
        return str;
    }
    public static int toInt(String str,int def) {
       try{
           return Integer.parseInt(str);
       }catch (Exception e){
       }
        return def;
    }
}
